<?php

//路由绑定 第二种模式  

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

echo '<pre>';
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

$channel->exchange_declare('direct_logs', 'direct', false, false, false);

$data = "xiguan";
// $data =json_encode($data);

$msg = new AMQPMessage($data);
$routing_key  ='keys';
$channel->basic_publish($msg,'direct_logs',$routing_key);


echo " [x] Sent ",$routing_key,':',$data," \n"; 

$channel->close();
$connection->close();